<?php
class DealCommentController extends BrowseControllerBase {
	/**
	 * GrouponDataService object
	 *
	 * @var GrouponDataService object
	 */
	public $grouponDataService = null;

	public $dealsDataService = null;
	/**
	 * GrouponCommentDataService object
	 *
	 * @var GrouponCommentDataService object
	 */
	public $grouponCommentDataService = null;
	
	/**
	 *
	 * DealOrderDataService
	 * @var DealOrderDataService Object
	 */
	public $dealOrderDataService = null;
	
	/**
	 *
	 * UsersDataService Object
	 * @var UsersDataService object
	 */
	public $userDataService = null;
	
	public $currentUserId = null;
	/**
	 * Constructor of index
	 */
	public $dealCommentDataService;
	public function __construct() {
		parent::__construct ();
		
		$this->grouponDataService = new GrouponDataService ();
		//
		$this->dealsDataService = new DealsDataService ();
		
		$this->currentUserId = $this->authentication->getCurrentUserId ();
		$this->dealCommentDataService = new DealCommentDataService();
	}
	
	//show all list
	public function indexAction() {
		$id = $this->getQuery ( 'id' );
		if ($id == '') {
			$id = $this->getPost ( 'id', '' );
		}
		$id = intval ( $id );
		//city
		$city = $this->getQuery ( 'city' );
		if ($city == '') {
			$city = $this->getPost ( 'city', 1 );
		}
		
		//get Deal
		$dealEntity = $this->dealsDataService->getById ( $id );
		// Get data
		$grouponEntity = $this->grouponDataService->getById ( $dealEntity->groupon_id );
		//get List Comment
			$listComment = $this->dealCommentDataService->getListComment($id);			
		//assign to view
		$this->smarty->assign ( 'listComment', $listComment );
		// cai nay de khi foreach comment, co dc user id, roi goi doi tuong userEn lay hinh anh user.
		$this->smarty->assign('userEntity', new UserEntity());
		
		$this->smarty->assign ( 'grouponEntity', $grouponEntity );
		$this->smarty->assign ( 'dealsEntity', $dealEntity );
		$this->smarty->assign ( 'SMARTY_CONTENT_PATH', 'Browse/DealComment/deal_comment.tpl' );
		$this->smarty->display ( APPLICATION_PATH . '/Layouts/Browse/MainLayoutDetailAll.tpl' );
	}
	public function commentAction(){
		$comment_text = $this->getPost('comment_text', '');
		$user_id= $this->getPost('user_id','');
		$deal_id= $this->getPost('deal_id','');
		$dealCommentEntity = $this->dealCommentDataService->beforeCreate();
		$dealCommentEntity->comment_text = $comment_text;
		$dealCommentEntity->user_id= $user_id;
		$dealCommentEntity->deal_id= $deal_id;
		$dealCommentEntity->default = 0;
		$comment_id = $this->dealCommentDataService->create($dealCommentEntity);
		//get user subject
		$userDataService = new UserDataService();
		$userEntity = $userDataService->getById($user_id);
		$data = array(
			'comment_text' => $comment_text,
			'fullname' => $userEntity->fullname,
			'datetime' => $dealCommentEntity->creation_date,
			'picture' => $userEntity->getImage()
		);
		echo Zend_Json::encode($data);
//		$commentDataservice= new CommonDataService();
//		$dealsEntity= $dealCommentEntity
		exit();
	}
}
?>